export const allTodoList = [
  {
    name: "吃中午饭",
    done: false,
  },
  {
    name: "学习 react",
    done: false,
  },
  {
    name: "使用node做项目",
    done: false,
  },
  {
    name: "打游戏",
    done: false,
  },
  {
    name: "刷面试题",
    done: false,
  },
  {
    name: "上班打卡",
    done: false,
  },
  {
    name: "看电视剧",
    done: false,
  },
  {
    name: "收拾屋子",
    done: false,
  },
  {
    name: "网站备案",
    done: false,
  }
]

export const getTodo: GetTodo = () => {
  return new Promise((resolve, reject) => {
    setTimeout(
      () => {
        const obj: any = {}
        // 随机选出三条 todo
        const data = allTodoList.sort((x, y) => {
          return Math.random() > 0.5 ? -1 : 1
        }).slice(0, 3)
        // 转换格式 
        data.map((item: Todo, index: number) => {
          obj[index.toString()] = item
        })
        resolve(obj)
      }, 300)
  })
}